<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>用户登录</title>
    <meta name="keywords" content="layui,ui,ui框架,前端框架,JS组件">
    <meta name="description"
          content="layui 是一套开源的 Web UI 解决方案，其内部采用的是自身经典的模块化规范，并遵循原生 HTML/CSS/JS 的开发方式，极易上手，拿来即用。其外在极简，却又不失饱满的内在，体积轻盈，组件丰盈，从核心代码到使用方法的每一处细节都经过精心雕琢，非常适合网页界面的快速开发。">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <script type="text/javascript" src="js/layui/layui.all.js"></script>
    <link rel="stylesheet" href="js/layui/css/layui.css"/>
    <script src="js/layui/layui.config.js"></script>
    <link rel="stylesheet" href="css/login.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div id="container">
    <div></div>
    <div class="admin-login-background">
        <div class="admin-header">
            <span>layuimini</span>
        </div>
        <div>
            <i class="layui-icon layui-icon-username admin-icon"></i>
            <input type="text" id="username" name="username" placeholder="请输入用户名" lay-verify="required"
                   autocomplete="off" class="layui-input admin-input admin-input-username">
        </div>
        <div>
            <i class="layui-icon layui-icon-password admin-icon"></i>
            <input type="password" id="password" name="password" placeholder="请输入密码" lay-verify="required"
                   autocomplete="off" class="layui-input admin-input">
        </div>
        <!--            <div>-->
        <!--                <input type="text" name="captcha" placeholder="请输入验证码" autocomplete="off" class="layui-input admin-input admin-input-verify" value="xszg">-->
        <!--                <img class="admin-captcha" width="90" height="30" src="../images/captcha.jpg">-->
        <!--            </div>-->
        <button class="layui-btn admin-button" lay-submit="" lay-filter="login">登 陆</button>
    </div>
</div>
</body>
<script>
    layui.use(['form', 'layer', 'axios'],
        function () {
            var form = layui.form,
                layer = layui.layer;
            //监听提交
            form.on('submit(login)',
                function (data) {
                    //var captcha=document.getElementById("captcha").value;
                    var username = document.getElementById("username").value;
                    var password = document.getElementById("password").value;

                    axios.post('/user/login', {
                        name: username,
                        password: password
                    }).then(function (response) {
                        const res = response.data;
                        if (response.status == 200) {
                            if (res.code == 200 && res.data.token) {
                                window.localStorage.setItem("accessToken", res.data.token);
                                layer.msg('登录成功', function () {
                                    window.location = 'index.html';
                                });
                            }else{
                                layer.msg("fail");
                            }
                        }
                    }).catch(function (error) {
                        console.log(error);
                    });
                });
        });
</script>
</html>